<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('原料区库存明细')"/>
    <style>
        [v-cloak] {
            display: none;
        }
        .el-date-editor.el-input, .el-date-editor.el-input__inner {
            width: 200px!important;
        }
        .el-input__icon {
            line-height: 0!important;
        }
        .tag {
            display: inline-block;
            padding: 0 5px;
            line-height: 22px;
            color: #FFFFFF;
            border-radius: 3px;
        }
        .disabled{
            pointer-events: none;
            cursor: not-allowed !important;
            background: #ccc !important;
        }
        .floatWrap{
            font-size: 14px;
            line-height: 24px;
            display: flex;
            margin-top: 5px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            物料编码：<input type="text" id="itemCode" name="itemCode"/>
                        </li>
                        <li>
                            批次：<input type="text" id="batch" name="batch"/>
                        </li>
                        <li>
                            商家：<input type="text" id="supplierName" name="supplierName"/>
                        </li>
                        <li>
                            质检状态：
                            <select name="billInState">
                                <option value="">全部</option>
                                <option value="1">合格</option>
                                <option value="2">待检</option>
                                <option value="3">不合格</option>
                                <option value="4">异常</option>
                                <option value="5">试作品</option>
                            </select>
                        </li>
                        <li>
                            状态：
                            <select name="state">
                                <option value="">全部</option>
                                <option value="1">正常</option>
                                <option value="2">冻结</option>
                                <option value="3">未入库</option>
                                <option value="4">在途</option>
                            </select>
                        </li>
                        <li>
                            <label>入库时间：</label>
                            <el-date-picker
                                    name="startTime"
                                    v-model="timeA"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    type="datetime"
                                    @change="compareAB"
                                    placeholder="开始时间">
                            </el-date-picker>
                            <span>-</span>
                            <el-date-picker
                                    name="endTime"
                                    v-model="timeB"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    type="datetime"
                                    @change="compareAB"
                                    placeholder="结束时间">
                            </el-date-picker>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()" @click="resetTime()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
<!--            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="in:boxItem:exportRevolutionStorage">-->
<!--                <i class="fa fa-download"></i> 导出全部-->
<!--            </a>-->
            <a class="btn btn-success" @click="tsck">
                特殊出库
            </a>
            <a class="btn btn-info" @click="partExcel()" shiro:hasPermission="in:boxItem:partExcelRevolutionStorage">
                <i class="fa fa-download"></i> 部分导出
            </a>
            <a class="btn btn-primary" onclick="$.table.print()">
                <i class="fa fa-plus"></i> 打印
            </a>
            <a class="btn btn-primary" @click="frozen">
                冻结
            </a>
            <a class="btn btn-primary" @click="unfrozen">
                解冻
            </a>
            <a class="btn btn-primary" @click="scpd">
                生成盘点单
            </a>
            <a class="btn btn-primary" @click="zlzh">
                质量转换
            </a>
            <a class="btn btn-primary" @click="pczh">
                批次转换
            </a>

<!--            <div class="floatWrap">-->
<!--                <div>合计：</div>-->
<!--                <div>共有哪条明细</div>-->
<!--                <div>库存总重量233Kg</div>-->
<!--            </div>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true" style="white-space: nowrap"></table>
        </div>
    </div>
    <el-dialog
            title="移库"
            :visible.sync="dialogVisible"
            width="40%"
            destroy-on-close
            :before-close="handleClose">
        <el-form :model="form" :inline="true" ref="dynamicValidateForm">
            <el-form-item label="货位" prop="cellCode" :rules="[
              { required: true, message: '请选择货位', trigger: 'change' }
            ]">
                <el-cascader ref="cascader" @change="handleChange" size="small" v-model="form.cellCode" :props="props"></el-cascader>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="handleClose">取 消</el-button>
            <el-button size="small" type="primary" @click="yk">确 定</el-button>
          </span>
    </el-dialog>
    <el-dialog
            title="质量转换"
            :visible.sync="dialogVisible1"
            width="40%"
            destroy-on-close
            :before-close="handleClose1">
        <el-form :model="form1" :inline="true" ref="dynamicValidateForm1">
            <el-form-item label="质量状态" prop="billInState" :rules="[
              { required: true, message: '请选择质量状态', trigger: 'change' }
            ]">
                <el-select v-model="form1.billInState" placeholder="请选择质量状态">
                    <el-option label="合格" value="1"></el-option>
                    <el-option label="待检" value="2"></el-option>
                    <el-option label="不合格" value="3"></el-option>
                    <el-option label="异常" value="4"></el-option>
                    <el-option label="试作品" value="5"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="handleClose1">取 消</el-button>
            <el-button size="small" type="primary" @click="tjzl">确 定</el-button>
          </span>
    </el-dialog>
    <el-dialog
            title="批次转换"
            :visible.sync="dialogVisible2"
            width="40%"
            destroy-on-close
            :before-close="handleClose2">
        <el-form :model="form2" :inline="true" ref="dynamicValidateForm2">
            <el-form-item label="批次" prop="batch" :rules="[
              { required: true, message: '请输入批次', trigger: 'change' }
            ]">
                <el-input v-model="form2.batch" placeholder="批次"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="handleClose2">取 消</el-button>
            <el-button size="small" type="primary" @click="tjpc">确 定</el-button>
          </span>
    </el-dialog>
    <el-dialog
            title="注意:点击确定按钮立刻出库"
            :visible.sync="dialogVisible3"
            width="40%"
            destroy-on-close
            :before-close="handleClose3">
        <el-form :model="form3" :inline="true" ref="dynamicValidateForm3">
            <el-form-item label="SAP出库计划单号" prop="sapNo" :rules="[
              { required: true, message: '请输入SAP单号', trigger: 'change' }
            ]">
                <el-input v-model="form3.sapNo" placeholder="SAP单号"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="handleClose3">取 消</el-button>
            <el-button size="small" type="primary" @click="tjck">确 定</el-button>
          </span>
    </el-dialog>
</div>

<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "in/boxItem";
    let id = 0;
    var app = new Vue({
        el: '.container-div',
        data() {
            return {
                cellList: [],
                shelfId: '',
                cellCode: '',
                id: '',
                form: {
                    cellCode:[]
                },
                form1: {
                    billInState:''
                },
                form2: {
                    batch: ''
                },
                form3: {
                    sapNo: ''
                },
                timeA: '',
                timeB: '',
                dialogVisible: false,
                dialogVisible1: false,
                dialogVisible2: false,
                dialogVisible3: false,
                props: {
                    lazy: true,
                    lazyLoad (node, resolve) {
                        const { level } = node;
                        console.log(node)
                        setTimeout(() => {
                            // 第一級
                            if (node.level == 0) {
                                console.log(node)
                                $.ajax({
                                    url: prefix+ "/findPai",
                                    type: "POST",
                                    error: function(request){
                                        $.modal.alertError("系统错误");
                                    },
                                    success: function(data){
                                        console.log(data)
                                        const nodes = data.map((item, index) => ({
                                            value: item.spai,
                                            label: `${item.spai}排`,
                                            leaf:node.level >= 3
                                        }));
                                        resolve(nodes);
                                    }
                                })
                            }
                            // 第二級
                            if(node.level == 1){
                                $.ajax({
                                    url: prefix+ "/findLie",
                                    type: "POST",
                                    data: {
                                        sPai: node.value,
                                    },
                                    error: function(request){
                                        $.modal.alertError("系统错误");
                                    },
                                    success: function(data){
                                        console.log(data)
                                        const nodes = data.map((item, index) => ({
                                            value: item.slie,
                                            label: `${item.slie}列`,
                                            leaf:node.level >= 3
                                        }));
                                        resolve(nodes);
                                    }
                                })
                            }
                            // 第3級
                            if(node.level == 2){
                                $.ajax({
                                    url: prefix+ "/findCeng",
                                    type: "POST",
                                    data: {
                                        sPai: node.path[0],
                                        sLie: node.value
                                    },
                                    error: function(request){
                                        $.modal.alertError("系统错误");
                                    },
                                    success: function(data){
                                        console.log(data)
                                        const nodes = data.map((item, index) => ({
                                            value: item.sfloor,
                                            label: `${item.sfloor}层`,
                                            leaf:node.level >= 3
                                        }));
                                        resolve(nodes);
                                    }
                                })
                            }
                            // 第3級
                            if(node.level == 3){
                                // Ajax請求數據，填充選擇框，傳遞上一級參數
                                $.ajax({
                                    url: prefix+ "/findCell",
                                    type: "POST",
                                    data: {
                                        sPai: node.path[0],
                                        sLie: node.path[1],
                                        sFloor: node.path[2]
                                    },
                                    error: function(request){
                                        $.modal.alertError("系统错误");
                                    },
                                    success: function(data){
                                        console.log(data)
                                        const nodes = data.map((item, index) => ({
                                            value: item.cellCode,
                                            label: item.cellCode,
                                            key: item.shelfId,
                                            leaf:node.level >= 3
                                        }));
                                        resolve(nodes);
                                    }
                                })
                            }
                        }, 100);
                    }
                }
            };
        },
        methods: {
            handleChange(value) {
                this.shelfId = this.$refs.cascader.getCheckedNodes()[0].data.key;
                this.cellCode = this.$refs.cascader.getCheckedNodes()[0].data.value;
            },
            tjpc() {
                var that = this;
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                console.log(rows)
                this.$refs['dynamicValidateForm2'].validate((valid) => {
                    if (valid) {
                        console.log(rows)
                        var boxItemList = [];
                        for (var i=0; i<rows.length; i++) {
                            boxItemList.push({id: rows[i], batch: that.form2.batch})
                        }
                        $.ajax({
                            url: prefix+ "/updateBatch",
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json;charset-UTF-8",
                            data: JSON.stringify(boxItemList),
                            error: function(request){
                                $.modal.alertError("系统错误");
                            },
                            success: function(data){
                                console.log(data)
                                if (data.code == 200) {
                                    that.handleClose2();
                                    $.modal.msgSuccess('已完成');
                                    $.table.refresh();
                                }
                            }
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            tjck() {
                var that = this;
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                var rowState = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectColumns('state') : $.table.selectColumns($.table._option.uniqueId);
                console.log(rowState)
                this.$refs['dynamicValidateForm3'].validate((valid) => {
                    if (valid) {
                        console.log(rows)
                        var boxItemList = [];
                        for (var i=0; i<rows.length; i++) {
                            boxItemList.push({
                                id: rows[i],

                                sapNo: that.form3.sapNo
                            })
                        }
                        $.ajax({
                            url: prefix+ "/spOutBoxItem",
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json;charset-UTF-8",
                            data: JSON.stringify(boxItemList),
                            error: function(data){
                                $.modal.alertError("系统错误");
                            },
                            success: function(data){
                                console.log(data)
                                if (data.code == 200) {
                                    that.handleClose3();
                                    $.modal.msgSuccess('已完成');
                                    $.table.refresh();
                                }
                            }
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            tjzl() {
                var that = this;
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                console.log(rows)
                this.$refs['dynamicValidateForm1'].validate((valid) => {
                    if (valid) {
                        console.log(rows)
                        var boxItemList = [];
                        for (var i=0; i<rows.length; i++) {
                            boxItemList.push({id: rows[i], billInState: that.form1.billInState})
                        }
                        $.ajax({
                            url: prefix+ "/updateBillInState",
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json;charset-UTF-8",
                            data: JSON.stringify(boxItemList),
                            error: function(request){
                                $.modal.alertError("系统错误");
                            },
                            success: function(data){
                                console.log(data)
                                if (data.code == 200) {
                                    that.handleClose1();
                                    $.modal.msgSuccess('已完成');
                                    $.table.refresh();
                                }
                            }
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            zlzh() {
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    this.dialogVisible1 = true;
                }
            },
            pczh() {
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    this.dialogVisible2 = true;
                }
            },
            tsck() {
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    this.dialogVisible3 = true;
                }
            },
            yk() {
                var that = this;
                this.$refs['dynamicValidateForm'].validate((valid) => {
                    if (valid) {
                        console.log(this.form.cellCode)
                        $.ajax({
                            url: prefix+ "/moveCell ",
                            type: "POST",
                            data: {
                                cellCode: that.cellCode,
                                id: that.id,
                                shelfId: that.shelfId
                            },
                            error: function(request){
                                $.modal.alertError("系统错误");
                            },
                            success: function(data){
                                console.log(data)
                                if (data.code == 200) {
                                    that.handleClose();
                                    $.modal.msgSuccess('已完成');
                                    $.table.refresh();
                                }
                            }
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            handleClose() {
                this.$refs['dynamicValidateForm'].resetFields();
                this.$refs.cascader.$refs.panel.clearCheckedNodes();
                this.dialogVisible = false;
            },
            handleClose1() {
                this.$refs['dynamicValidateForm1'].resetFields();
                this.form1.billInState = '';
                this.dialogVisible1 = false;
            },
            handleClose2() {
                this.$refs['dynamicValidateForm2'].resetFields();
                this.form2.batch = '';
                this.dialogVisible2 = false;
            },
            handleClose3() {
                this.$refs['dynamicValidateForm3'].resetFields();
                this.form3.sapNo = '';
                this.dialogVisible3 = false;
            },
            //时间对比
            compareAB: function(){
                if(this.timeA != '' && this.timeA != null){
                    if(this.timeB != '' && this.timeB != null){
                        var a = new Date(this.timeA);
                        var b = new Date(this.timeB);
                        if(a > b){
                            $.modal.alertError("结束时间需大于开始时间，请重新选择！！");
                            this.timeA = '';
                            this.timeB = '';
                        }
                    }else{
                        this.timeB = '';
                    }
                }else{
                    this.timeA = '';
                    if(this.timeB == null){
                        this.timeB = '';
                    }
                }
            },
            //清空时间
            resetTime(){
                this.timeA = '';
                this.timeB = '';
            },
            scpd() {
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    $.modal.confirm("确认要生成选中的" + rows.length + "条数据吗?", function(){
                        var url = "/boxitemcheck/getCheck";
                        console.log(rows)
                        var data = {"id": rows.join()};
                        $.ajax({
                            url: url,
                            type: "POST",
                            data: data,
                            error: function(request){
                                $.modal.alertError("系统错误");
                            },
                            success: function(data){
                                if(data.code == 0){
                                    $.modal.msgSuccess('已完成');
                                    $.table.refresh();
                                }else{
                                    $.modal.alertError(data.msg);
                                }
                            }
                        })
                    });
                }
            },
            // 冻结
            frozen() {
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    $.modal.confirm("确认要冻结选中的" + rows.length + "条数据吗?", function(){
                        var url = prefix + "/blockedBoxItem";
                        console.log(rows)
                        var data = {"ids": rows.join()};
                        $.ajax({
                            url: url,
                            type: "POST",
                            data: data,
                            error: function(request){
                                $.modal.alertError("系统错误");
                            },
                            success: function(data){
                                if(data.code == 0){
                                    $.modal.msgSuccess('已完成');
                                    $.table.refresh();
                                }else{
                                    $.modal.alertError(data.msg);
                                }
                            }
                        })
                    });
                }
            },
            unfrozen() {
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    $.modal.confirm("确认要解冻选中的" + rows.length + "条数据吗?", function(){
                        var url = prefix + "/unfreezeBoxItem";
                        console.log(rows)
                        var data = {"ids": rows.join()};
                        $.ajax({
                            url: url,
                            type: "POST",
                            data: data,
                            error: function(request){
                                $.modal.alertError("系统错误");
                            },
                            success: function(data){
                                if(data.code == 0){
                                    $.modal.msgSuccess('已完成');
                                    $.table.refresh();
                                }else{
                                    $.modal.alertError(data.msg);
                                }
                            }
                        })
                    });
                }
            },
            //部分导出
            partExcel(){
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    $.modal.confirm("确认要导出选中的" + rows.length + "条数据吗?", function(){
                        var url = prefix + "/partExcelRevolutionStorage";
                        var data = {"ids": rows.join()};
                        $.post(url, data, function(result){
                            if(result.code == web_status.SUCCESS){
                                window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                            }else if(result.code == web_status.WARNING){
                                $.modal.alertWarning(result.msg);
                            }else{
                                $.modal.alertError(result.msg);
                            }
                            $.modal.closeLoading();
                        });
                    });
                }
            }
        }
    })

    $(function() {
        var options = {
            url: "/in/boxItem/selectBoxItemDetail",
            exportUrl: prefix + "/exportRevolutionStorage",
            detailUrl: "/in/boxItem/boxItemDetail",
            showFooter: true,
            modalName: "原料区库存明细",
            pageSize: '50',
            // onLoadSuccess: function (data){
            //     console.log(data)
            // },
            columns: [
                {
                    checkbox: true,
                    formatter: function(value, row, index){
                        if(row.state != 4){
                            return { disabled : false}
                        }else{
                            return { disabled : true}
                        }
                    }
                },
                {
                    field: 'id',
                    title: '序号',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'batch',
                    title: '批次',
                    align: 'center',
                    footerFormatter: function(value){
                        var boxSum = 0;
                        var weightSum = 0;
                        for(var i in value){
                            boxSum = Number(value[i].boxSum);
                            weightSum = Number(value[i].weightSum);

                        }
                        return '托盘合计&ensp;:&ensp;'+boxSum+"托&ensp;&ensp;&ensp;"+
                            '重量合计&ensp;:&ensp;'+weightSum+"kg";
                    }
                },
                {
                    field: 'boxCode',
                    title: '托盘编码',
                    align: 'center'
                },
                {
                    field: 'itemCode',
                    title: '物料编码',
                    align: 'center'
                },
                {
                    field: 'itemName',
                    title: '物料描述',
                    align: 'center'
                },
                {
                    field: 'sort',
                    title: '物料类型',
                    align: 'center',
                    formatter: function(value, row, index){
                        var actions = [];
                        if(value == 1){
                            actions.push("<span>钢材</span>");
                        }else if(value == 2){
                            actions.push("<span>铜材</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'billInState',
                    title: '质检状态',
                    align: 'center',
                    formatter: function(value, item, index){
                        var actions = [];
                        if(value == 1){
                            actions.push("<span class='tag' style='background-color: #fcb529'>合格</span>");
                        } else if (value == 2) {
                            actions.push("<span class='tag' style='background-color: #f8ac59'>待检</span>");
                        }else if (value == 3) {
                            actions.push("<span class='tag' style='background-color: #999999'>不合格</span>");
                        }else if (value == 4) {
                            actions.push("<span class='tag' style='background-color: red'>异常</span>");
                        }
                        else if (value == 5) {
                            actions.push("<span class='tag' style='background-color: red'>试作品</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'state',
                    title: '状态',
                    align: 'center',
                    formatter: function(value, item, index){
                        var actions = [];
                        if(value == 1){
                            actions.push("<span class='tag' style='background-color: #fcb529'>正常</span>");
                        } else if (value == 2) {
                            actions.push("<span class='tag' style='background-color: #f8ac59'>冻结</span>");
                        }else if (value == 3) {
                            actions.push("<span class='tag' style='background-color: #999999'>入库中</span>");
                        }else if (value == 4) {
                            actions.push("<span class='tag' style='background-color: #999999'>前往线边仓</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'supplierName',
                    title: '供应商名称',
                    align: 'center'
                },
                {
                    field: 'memo',
                    title: '库位',
                    align: 'center'
                },
                {
                    field: 'weight',
                    title: '库存重量',
                    align: 'center'
                },
                {
                    field: 'unit',
                    title: '单位',
                    align: 'center'
                },
                {
                    field: 'makeTime',
                    title: '生产日期',
                    align: 'center',
                    formatter: function(value, row, index){
                        if (value == null) {
                            return '-';
                        } else {
                            var now = new Date().getTime();
                            var time = new Date(value).getTime();
                            var cz = 86400000*365*row.time;
                            var tt = now-time;
                            var actions = [];
                            var val = value.slice(0, 10)
                            if(tt > cz){
                                actions.push("<span style='color: red'>"+ val +"</span>");
                            } else {
                                actions.push("<span>"+val+"</span>");
                            }
                            return actions.join('');
                        }
                    }
                },
                {
                    field: 'takeTime',
                    title: '入库日期',
                    align: 'center',
                    formatter: function(value, row, index){
                        if (value == null) {
                            return '-';
                        } else {
                            var now = new Date().getTime();
                            var time = new Date(value).getTime();
                            var cz = 86400000*365*row.time;
                            var tt = now-time;
                            var actions = [];
                            var val = value.slice(0, 19)
                            if(tt > cz){
                                actions.push("<span style='color: red'>"+ val +"</span>");
                            } else {
                                actions.push("<span>"+val+"</span>");
                            }
                            return actions.join('');
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    events: {
                        'click .detail': function(e, value, rowData, index){
                            app.dialogVisible = true;
                            app.id = rowData.id;
                        }
                    },
                    formatter: function(value, row, index){
                        var actions = [];
                        var editFlag = 'disabled';
                        if(row.state != 2){
                            editFlag = '';
                        }
                        actions.push('<span class="detail tag ' + editFlag + '" style="background-color: #3097b5;cursor: pointer;"><i class="fa fa-hand-pointer-o"></i> 移库</span>');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    // $('#bootstrap-table').on("load-success.bs.table", function (data) {
    //     $.table.onLoadSuccess();
    // });

    function onLoadSuccess1 (data) {
        console.log(data)
    }

    function open(title, url, width, height, callback){
        if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){
            width = 'auto';
            height = 'auto';
        }
        if($.common.isEmpty(title)){
            title = false;
        }
        if($.common.isEmpty(url)){
            url = "/404.html";
        }
        if($.common.isEmpty(width)){
            width = 800;
        }
        if($.common.isEmpty(height)){
            height = ($(window).height() - 250);
        }
        if($.common.isEmpty(callback)){
            callback = function(index, layero){
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler();
            }
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: title,
            content: url,
            btn: ['关闭'],
            shadeClose: true,
            cancel: function(index){
                return true;
            }
        });
    }
</script>
</body>
</html>
